var cgdstock = {
    fillData:function () {
        $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm':'cd'}, function (cddata) {
            $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm':'jzfs'}, function (data) {
                fillHtmxByCgd($.webPath() + '/cggl/cgdgl/cgdgl_cgmx?cgd.id=' + $("[name='cgd.id']").val() || '', cddata, data);
            })
        });
    }
}

function fillHtmxByCgd(href, cdOptions, fsOptions) {
    $("#cgd_mx").edatagrid({
            url:href,
            fitColumns:true,
            singleSelect:true,
            fit:true,
            checkOnSelect:false,
            selectOnCheck:false,
            rownumbers:true,
            toolbar:"#cgdgl_cgdmx_toolbar",
            columns:[
                [
                    {field:'wzgg.code', title:'物资编码', width:50, rowspan:2},
                    {field:'wzgg.name', title:'品名', width:40, rowspan:2},
                    {field:'wzgg.ggxh', title:'规格型号', width:30, rowspan:2},
                    {field:'cd.z', title:'产地', width:30, rowspan:2},
                    {title:'发货', colspan:2},
                    {field:'jzfs.id', editor:{type:'combobox', options:{
                        data:fsOptions,
                        valueField:'id',
                        textField:'z',
                        multiple:false,
                        panelHeight:'55'
                    }
                    }, formatter:function (value) {
                        for (var i = 0; i < fsOptions.length; i++) {
                            if (fsOptions[i].id == value) return fsOptions[i].z;
                        }
                        return value;
                    }, title:'记重方式', width:30, rowspan:2},
                    {title:'到货', colspan:3},
                    {field:'kh.khbm', editor:{type:'text'}, title:'卡号编码', hidden:true, rowspan:2},
                    {field:'hsj', title:'含税单价', width:20, rowspan:2},
                    {field:'bhsj', title:'不含税单价', width:30, rowspan:2},
                    {field:'bz', title:'备注', width:30, rowspan:2}
                ],
                [

                    {field:'js', title:'件数', precision:4, width:20},
                    {field:'sbsl', title:'重量', precision:4, width:20},
                    {field:'rkjs', editor:{type:'numberbox', options:{min:0, groupSeparator:','}}, title:'件数', width:20},
                    {field:'rkjz', editor:{type:'numberbox', options:{min:0, groupSeparator:','}}, title:'件重', width:20},
                    {field:'rksl', editor:{type:'numberbox', options:{min:0, groupSeparator:','}}, title:'重量', width:20}
                ]
            ],
            onSelect:function (rowIndex, rowData) {
                //获取每个单元格
                $("#cgd_mx").edatagrid('editRow', rowIndex);
            }
        }
    )
}

$(function () {
    cgdstock.fillData();
    setTimeout(function () {
        $('#cgdglForm').tabs('select', "入库明细");
    }, 100);
})